package ooo.reindeer.cedf.components.flow;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.LinkedHashMap;

public class FlowResult {

    private static ObjectMapper mapper = new ObjectMapper();

    private final String id;
    private final String flow_id;
    private final LinkedHashMap<String, Object> map;

    public FlowResult(String id, String flow_id) {
        this.id = id;
        this.flow_id = flow_id;
        this.map = new LinkedHashMap<String, Object>();
    }

    public void addStep(Step step) {
        map.put(step.getId(), null);
    }

    public void addResult(Step step, Object result) {
        map.put(step.getId(), result);
    }

    public String getId() {
        return id;
    }

    public String getFlowId() {
        return flow_id;
    }

    public LinkedHashMap<String, Object> getMap() {
        return map;
    }

    @Override
    public String toString() {
        try {
            return mapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
}
